class Solution {
    public int numberOfAlternatingGroups(int[] colors) {
        int n = colors.length;
        int ans = 0;
        for (int i = 2; i < n; i++) {
            if(colors[i] == colors[i-2] && colors[i] != colors[i-1]){
                ans++;
            }
        }
        if(colors[0] == colors[n-2] && colors[0]!= colors[n-1]){
            ans++;
        }
        return ans;
    }
}